package com.tgu.controller;

import com.tgu.service.IIconsService;
import com.tgu.utils.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("portal/icons")
public class IconsController {

    @Autowired
    private IIconsService iconsService;

    /*
    这代码有问题。static的静态资源，不用返回文件的二进制数据。直接输入路径访问就行。
    @GetMapping("/{name}")
    public byte[] getIconById(@PathVariable String name) throws IOException {
        return iconsService.getIconByName(name);
    }
    */

    @PostMapping("/upLoad")
    public String upLoadImg(HttpServletRequest req, @RequestParam("file") MultipartFile file, Model m) {
        return iconsService.upLoadImg(req, file, m);
    }

    @GetMapping("/getUpLoadedImg/{fileName}")
    public byte[] getUpLoadedImg(@PathVariable String fileName) {
        return iconsService.getUpLoadedImg(fileName);
    }
}
